fix(mysql): prevent panic on NULL values and hanging connections with OceanBase - #114
Merged
Conversation
… OceanBase
Two fixes for MySQL adapter when connecting to OceanBase:
1. test_connection() used row.get::<String, _>().unwrap() which panics
when the database returns NULL (e.g. DATABASE() with no database
selected). Changed to use get_opt() which returns Option<Result<_, _>>
and gracefully handles NULL -> None.
2. connect() had no internal connection timeout — mysql_async v0.34
removed tcp_connect_timeout, so pool.get_conn() could hang forever
on unresponsive hosts. Added tokio::time::timeout wrapping both
get_conn() and query_drop("SELECT 1") using connect_timeout_secs.
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
…rdcoded timeouts Four HTTP-based adapters used hardcoded timeouts (ClickHouse/Turso/RQLite: 60s, HttpSql: 30s) instead of respecting the user's configured connect_timeout_secs from ConnectionConfig. - clickhouse.rs: build_client() 60s hardcoded -> connect_timeout_secs - turso.rs: build_client() 60s hardcoded -> connect_timeout_secs - rqlite.rs: build_client() 60s hardcoded -> connect_timeout_secs - http_sql.rs: connect() 30s hardcoded -> connect_timeout_secs Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Connecting to OceanBase (MySQL-compatible) has two critical issues:
1. Panic on NULL values in
test_connection()row.get::<String, _>().unwrap()usesFromValueforStringwhichpanic!s onValue::NULL. OceanBase returns NULL forDATABASE()when no database is selected, and potentially forUSER()depending on configuration.2. Connection hangs indefinitely
MySQLAdapter::connect()had no internal connection timeout. Thetcp_connect_timeoutAPI was removed in mysql_async v0.34 with no replacement, sopool.get_conn().awaitcould hang forever on unresponsive hosts.The
tokio::time::timeoutinconnect_serveronly covers one code path — the "Test Connection" dialog path (server::test_connection) callsconnect()directly with zero timeout protection.Fix
1. Safe NULL handling in
test_connection()Replaced
row.get::<String, _>().unwrap()withrow.get_opt::<String, _>()which returnsOption<Result<String, FromValueError>>. A match onSome(Ok(val))gracefully resolves NULL toNoneinstead of panicking.2. Adapter-level connection timeout
Added
tokio::time::timeoutwrappingpool.get_conn()andconn.query_drop(\"SELECT 1\")insideconnect(), usingself.config.connect_timeout_secs. This applies to ALL call paths (both "Connect" and "Test Connection") since the timeout lives at the adapter level.Testing
cargo checkclean